package com.huabo.contract.service.impl;

import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.oracle.entity.TblLegalNegotiaterecord;
import com.huabo.contract.oracle.mapper.TblLegalNegotiaterecordMapper;
import com.huabo.contract.service.TblLegalNegotiateRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TblLegalNegotiateRecordServiceImpl implements TblLegalNegotiateRecordService {

    @Resource
    private TblLegalNegotiaterecordMapper tblLegalNegotiaterecordMapper;

    @Override
    public List<TblLegalNegotiaterecord> findListBynegotiaId(Integer negotiaId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return this.tblLegalNegotiaterecordMapper.findListBynegotiaId(negotiaId);
        } else {
            return this.tblLegalNegotiaterecordMapper.findListBynegotiaId(negotiaId);
        }
    }

    @Override
    public void saveNegotiateRecord(TblLegalNegotiaterecord record) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalNegotiaterecordMapper.saveNegotiateRecord(record);
        } else {
            this.tblLegalNegotiaterecordMapper.saveNegotiateRecord(record);
        }
    }

    @Override
    public TblLegalNegotiaterecord findById(Integer recordId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return this.tblLegalNegotiaterecordMapper.findById(recordId);
        } else {
            return this.tblLegalNegotiaterecordMapper.findById(recordId);
        }
    }

    @Override
    public void modifyNegotiateRecord(TblLegalNegotiaterecord oldRecord) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalNegotiaterecordMapper.updateModifyNegotiateRecord(oldRecord);
        } else {
            this.tblLegalNegotiaterecordMapper.updateModifyNegotiateRecord(oldRecord);
        }
    }

    @Override
    public void removeNegitiateRecord(Integer recordId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalNegotiaterecordMapper.removeNegitiateRecord(recordId);
        } else {
            this.tblLegalNegotiaterecordMapper.removeNegitiateRecord(recordId);
        }
    }

    @Override
    public void findByNegotiaId(PageInfo<TblLegalNegotiaterecord> pageInfo, Integer negotiaId) {

        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalNegotiaterecordMapper.findByNegotiaid(pageInfo, negotiaId));
            pageInfo.setTotalRecord(tblLegalNegotiaterecordMapper.findByNegotiaidCount(negotiaId));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalNegotiaterecordMapper.findByNegotiaid(pageInfo, negotiaId));
            pageInfo.setTotalRecord(tblLegalNegotiaterecordMapper.findByNegotiaidCount(negotiaId));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        }
    }
}
